<?php

class Core_Backend_Component_Article_View_Category_Index extends Core_Backend_Share_View_Grid {

    protected function buildToolbar($toolbar) {
    	parent::buildToolbar($toolbar);
    	$group = $toolbar->createGroup();
        $group->addLink($this->getUrl(NULL, 'create'), $this->__('share.button.create'));
    }

    protected function buildGrid($grid) {
    	$this->getTemplate()->assignMulti(array('areas'=>$this->getAreas(), 'current_area_id'=>$this->getCurrentAreaId()));
        $filter = new Kd_Object($this->getRequest()->getParameter('filter'));
        $grid->setId('category_grid')
                ->setPrimaryKey('id')
                ->setAllowFilter(TRUE)
                ->setSortField($this->getRequest()->getQuery('sort', 'id'))
                ->setSortDirection($this->getRequest()->getQuery('dir', 'asc'))
                ->setSortUrlFormat($this->getSortUrl());
       $grid->addLabelColumn($this->__('share.label.name'), 'title', '{title}')
                ->setWidth(200)
                ->setTextboxFilter(NULL, NULL, $filter->getData('title'))->setSortField('title');
//        $grid->addLabelColumn($this->__('global.label.template'), 'template_name', '{template_name}')
//                ->setWidth(200)
//                ->setSortField('template_name')
//                ->getGrid()
        $grid->addLabelColumn($this->__('share.label.sef_url'), 'sef_url', '{sef_url}')->setSortField('sef_url');
        $grid->addLabelColumn($this->__('share.label.sorting'), 'sorting', '{sorting}')
                ->setWidth(40)
                ->setAlign('center')
                ->setSortField('sorting');
        $grid->addLabelColumn($this->__('share.label.creator'), 'creator', '{creator}')
                ->setSortField('creator')
                ->setWidth(100)
                ->getGrid()
                ->addDatetimeColumn($this->__('catalogue.label.created_time'), 'created_time', '{created_time}')
                ->setWidth(100)
                ->setSortField('created_time')
                ->getGrid();
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->addLinkColumn('#', 'sort', $this->getUrl(array('parent' => '{parent_id}'), 'sort'), $this->__('share.button.sort'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        $pagination->setUrlFormat($this->getPaginationUrl())->setRecordCount($this->getRecords());
        parent::buildPagination($pagination);
    }

}